//
// Created by 11510 on 2024/6/21.
//
#include <iostream>
#include <string>
#include <memory>
#include <vector>

using namespace std;


struct FILECloser{
    void operator()(FILE * fp){
        if(fp){
            fclose(fp);
            cout << "fclose(fp)" << endl;
        }
    }
};


void test1() {
    string msg = "this is a string";
#if 0
    unique_ptr<FILE, FILECloser> up(fopen("res.txt", "w+"));
#else
    FILECloser fp;
    shared_ptr<FILE> up(fopen("res.txt", "w+"), fp);
#endif
    fwrite(msg.c_str(), 1, msg.size(), up.get());
    /*fclose(up.get());*/
}

int main() {
    test1();
    return 0;
}